package com.sky.service.impl;

import com.sky.entity.Category;
import com.sky.entity.DishFlavor;
import com.sky.entity.Setmeal;
import com.sky.mapper.CommonMapper;
import com.sky.service.CommonService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CommonServiceImpl implements CommonService {
    @Autowired
    private CommonMapper commonMapper;

    /**
     * 总页面浏览
     * @param type
     * @return
     */
    @Override
    public List<Category> categoryList(Integer type) {
        return commonMapper.categoryList(type);
    }

    /**
     * 根据分类id查询套餐
     * @param id
     * @return
     */
    @Override
    public List<Setmeal> setmealList(Integer id) {
        return commonMapper.setmealList(id);
    }

    /**
     * 根据套餐id查询包含的菜品
     * @param id
     * @return
     */
    @Override
    public List<DishItemVO> setmealDishList(Long id) {
        return commonMapper.setmealDishList(id);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Override
    public List<DishVO> dishList(Long categoryId) {
        List<DishVO> dishVOList =  commonMapper.dishList(categoryId);
        for (DishVO dishVO : dishVOList) {
            List<DishFlavor> dishFlavorList = commonMapper.dishFlavorList(dishVO.getId());
            dishVO.setFlavors(dishFlavorList);
        }
        return dishVOList;
    }
}
